#-*-coding:utf-8-*-

""""
读取数据
"""
import pandas
import os


def get_file_name(data_path):
    train_dir = 'ai_challenger_sentiment_analysis_trainingset_20180816'
    train_file = 'sentiment_analysis_trainingset.csv'
    test_dir = 'ai_challenger_sentiment_analysis_testa_20180816'
    test_file = 'sentiment_analysis_testa.csv'
    dev_dir = 'ai_challenger_sentiment_analysis_validationset_20180816'
    dev_file = 'sentiment_analysis_validationset.csv'
    train_filename = os.path.join(data_path, train_dir, train_file)
    test_filename = os.path.join(data_path, test_dir, test_file)
    dev_filename = os.path.join(data_path, dev_dir, dev_file)
    files = {
        'train': train_filename,
        'dev': dev_filename,
        'test': test_filename
    }
    return files

def get_keys():
    keys = ['id', 'content', 'location_traffic_convenience',
           'location_distance_from_business_district', 'location_easy_to_find',
           'service_wait_time', 'service_waiters_attitude',
           'service_parking_convenience', 'service_serving_speed', 'price_level',
           'price_cost_effective', 'price_discount', 'environment_decoration',
           'environment_noise', 'environment_space', 'environment_cleaness',
           'dish_portion', 'dish_taste', 'dish_look', 'dish_recommendation',
           'others_overall_experience', 'others_willing_to_consume_again']
    return keys


class Datasets(object):
    def __init__(self, data_path):
        """
        data_path : 下载文件解压后的目录
        :param data_path:
        """
        self.data_path = data_path
        self.data_files = get_file_name(data_path)

    def _read_data(self, filename):
        return pandas.read_csv(filename)


    def train_data(self):
        """
        :return:
        """
        train_dataset = self._read_data(self.data_files['train'])
        return train_dataset


    def dev_data(self):
        """
        dev data
        :return:
        """
        dev_dataset = self._read_data(self.data_files['dev'])
        return dev_dataset

    def test_data_a(self):
        """
        test data
        :return:
        """
        test_dataset = self._read_data(self.data_files['test'])
        return test_dataset

    def data_set(self):
        """
        all dataSet
        :return:
        """
        dataset = {
            'train': self.train_data(),
            'dev': self.dev_data(),
            'testa': self.test_data_a()
        }
        return dataset


